package com.yiren.manager.service.impl.department;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.yiren.core.exception.MyException;
import com.yiren.core.repository.GenericRepository;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.Favorites;
import com.yiren.entity.YrCaregiver;
import com.yiren.entity.YrMealCard;
import com.yiren.manager.repository.messhall.YrMealCardRepositoty;
import com.yiren.manager.service.iface.department.YrCaregiverService;

@Service("yrCaregiverService")
public class YrCaregiverServiceImpl extends GenericServiceImpl<YrCaregiver, String> implements YrCaregiverService{

	@Autowired
	private YrMealCardRepositoty mealCardRepository;
	
	@Autowired
	public YrCaregiverServiceImpl(GenericRepository<YrCaregiver, String> repository) {
		super(repository);
	}

	@Transactional
	public void updateBetch(List<YrCaregiver> list) throws MyException {
		for(YrCaregiver entity : list){
			this.repository.save(entity);
		}
	}

	@Transactional
	public void addByFavorites(Favorites entitys) throws MyException {
		YrCaregiver caregiver = entitys.getFavorite(YrCaregiver.class);
		YrMealCard mealCard = entitys.getFavorite(YrMealCard.class);
		
		this.repository.save(caregiver);
		if(null!=mealCard){
			mealCardRepository.save(mealCard);
		}
	}
}
